<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/aaa/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/aaa/layuiadmin/style/admin.css" media="all">

</head>
<body>


















<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button id="school-addbtn" class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                        添加门店
                    </button>
                </div>
                <!--<div class="layui-inline">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="telphone"  placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="school-searchbtn" class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>-->
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-hide" id="school" lay-filter="school-filter"></table>

            <script src="/aaa/layuiadmin/layui/layui.js"></script>
            <script src="/aaa/layuiadmin/layui/layui-xtree.js"></script>
            <script type="text/html" id="school-bar">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="school-detail">查看</a>
                <a class="layui-btn layui-btn-xs" lay-event="school-edit">编辑</a>
            </script>
        </div>
    </div>
</div>


<form class="layui-form" id="addschoolform">
    <div id="school-addlayer" style="display: none;width: 360px">
        <input id="addschool-id"  type="hidden" autocomplete="off" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label">学校名称</label>
            <div class="layui-input-inline">
                <input type="text" name="schoolName" id="addschool-name" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">负责人电话</label>
            <div class="layui-input-inline">
                <input type="text" name="schoolTelephone" id="addschool-telephone" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">创建时间：</label>
            <div class="layui-input-inline">
                <input type="text" name="createTime" id="addschool-createtime" required  placeholder="yyyy-MM-dd" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveschool">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
<form class="layui-form" id="editschoolform">
    <div id="school-editlayer" style="display: none">
        <input type="hidden" name="schoolId" id="schoolId">
        <div class="layui-inline">
            <label class="layui-form-label">门店名称</label>
            <div class="layui-input-block">
                <input type="text" name="schoolName" id="schoolName" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="schoolTelephone" id="schoolTelephone"  placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveeditschool">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>


<script th:inline="none">
    layui.use(['table','form','laydate'], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem:'#addschool-createtime',
            type:'datetime'
        });

        form.on('submit(saveschool)',function (data) {
            var field = data.field;
            $.ajax({
                url:'/aaa/school/addSchool',
                type:'POST',
                data:field,
                success:function (data) {
                    if(data.code==100){

                        layer.closeAll();
                        layer.msg("添加成功");
                        table.reload('school');
                    }else if(data.code==200){
                        layer.closeAll();
                        layer.msg("添加失败");
                    }else{
                        layer.closeAll();
                        layer.msg("该学校已存在,添加失败");
                    }

                }
            });
            return false;
        });



        table.render({
            elem: '#school',
            url: '/aaa/school/getSchool',
            page: true,
            height:600,
            cols: [
                [
                    {field:'school_id',title:'学校id',align:'center'},
                    {field:'school',title:'学校名称',align:'center'},
                    {field:'schooltelephone',title:'负责人电话',align:'center'},
                    {field:'createtime',title:'创建时间',align:'center'},
                {title:'操作',toolbar:'#school-bar',align:'center'},
                ]
            ]
        });



        $('#school-addbtn').click(function () {
            layer.open({
                type: 1,
                title:'添加员工',
                content: $('#school-addlayer')
            });
            document.getElementById("addschoolform").reset();

        });


        form.on('submit(saveeditschool)',function (data) {
            var field = data.field;
            $.ajax({
                url:'/aaa/school/editSchool',
                type:'POST',
                data:field,
                success:function (data) {
                    if(data.code==100){
                        layer.closeAll();
                        layer.msg("修改成功");
                        table.reload('school');
                    }else if(data.code==200){
                        layer.closeAll();
                        layer.msg("修改失败");
                    }else{
                        layer.closeAll();
                        layer.msg("该学校已存在,请换个名称");
                    }

                }
            });
            return false;
        });


        table.on('tool(school-filter)', function(obj){
            var data = obj.data;
            if(obj.event === 'school-detail'){
                layer.open({
                    type: 2,
                    area: ['1300px', '800px'],
                    content: '/aaa/emp/getEmpPage?id='+data.school_id
                });
            } else if(obj.event === 'school-del'){
                layer.confirm('确定删除该行数据？', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'school-edit'){
                $("#schoolName").val(data.school);
                $("#schoolTelephone").val(data.schooltelephone);
                $("#schoolId").val(data.school_id);
                layer.open({
                    type: 1,
                    title:'编辑门店',
                    area: ['350px', '200px'],
                    content: $('#school-editlayer')
                });

            }
        });
    });
</script>
</body>
</html>